<template>
  <SvgFilters />
  <div class="tabs-container glass-effect">
    <div class="tabs-navigation">
      <button 
        v-for="tab in tabs" 
        :key="tab.id"
        class="tab-button"
        :class="{ active: activeTab === tab.id }"
        @click="selectTab(tab.id)"
        :aria-selected="activeTab === tab.id"
      >
        {{ tab.name }}
      </button>
    </div>
    
    <div class="tabs-content">
      <slot :active-tab="activeTab" />
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import SvgFilters from './SvgFilters.vue'

const props = defineProps({
  tabs: {
    type: Array,
    required: true,
    validator: (tabs) => {
      // 验证tabs数组中的每个对象是否包含id和name属性
      return tabs.every(tab => tab.id && tab.name)
    }
  },
  modelValue: {
    type: String,
    default: ''
  }
})

const emit = defineEmits(['update:modelValue'])

// 计算当前激活的选项卡
const activeTab = computed(() => {
  // 如果提供了modelValue且它存在于tabs中，则使用它
  if (props.modelValue && props.tabs.some(tab => tab.id === props.modelValue)) {
    return props.modelValue
  }
  // 否则使用第一个选项卡
  return props.tabs.length > 0 ? props.tabs[0].id : ''
})

// 选择选项卡
const selectTab = (tabId) => {
  emit('update:modelValue', tabId)
}
</script>

<style scoped>
.tabs-container {
  width: 100%;
  margin-bottom: 2rem;
}

/* 玻璃拟态效果 - 使用SVG滤镜实现液态玻璃 */
.glass-effect {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 0.5rem;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  filter: url(#liquidGlass);
}

/* 深色模式下的玻璃效果 */
[data-theme="dark"] .glass-effect {
  background: rgba(31, 41, 55, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
  filter: url(#liquidGlass);
}

.tabs-navigation {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.tab-button {
  padding: 0.75rem 1.5rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #64748b;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 0.375rem 0.375rem 0 0;
}

.tab-button:hover {
  background-color: #f8fafc;
  color: #334155;
}

.tab-button.active {
  color: #4f46e5;
  border-bottom-color: #4f46e5;
  background-color: #f0f9ff;
}

.tabs-content {
  padding: 1rem 0;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .tabs-navigation {
    flex-direction: column;
  }
  
  .tab-button {
    border-radius: 0.375rem;
    border-bottom: 2px solid transparent;
  }
  
  .tab-button.active {
    border-radius: 0.375rem;
    background-color: #f0f9ff;
  }
}
</style>